package com.toket.android.pushme.view;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.toket.android.pushme.R;
import com.toket.android.pushme.screen.MainScreen;

public class TopbarView extends AbstractView{
	
	private ImageView btn_option;
	
	public TopbarView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void initLayout() {
		// TODO Auto-generated method stub
		btn_option = (ImageView) screen.findViewById(R.id.btn_option);
	}
	
	public void setEnableButton(boolean isEnable){
		btn_option.setEnabled(isEnable);
	}
	
	@Override
	protected void initValue() {
		// TODO Auto-generated method stub
		btn_option.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				showConfirmDialog();
			}
		});
	}
	
	private void showConfirmDialog(){
		AlertDialog dialog = new AlertDialog.Builder(context).create();
	    dialog.setTitle(screen.getResources().getString(R.string.app_name));
	    dialog.setMessage(screen.getResources().getString(R.string.confirm_logout));
	    dialog.setCancelable(true);
	    dialog.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
	        public void onClick(DialogInterface dialog, int buttonId) {
	            ((MainScreen)screen).logout();
	        }
	    });
	    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() {
	        public void onClick(DialogInterface dialog, int buttonId) {
	        	dialog.dismiss();
	        }
	    });
	    dialog.setIcon(android.R.drawable.ic_dialog_alert);
	    dialog.show();
	}
	
	@Override
	public void cleanUp() {
		// TODO Auto-generated method stub
		
	}

}
